<%--
  Created by IntelliJ IDEA.
  User: Josh
  Date: 8/11/12
  Time: 8:25 AM
  To change this template use File | Settings | File Templates.
--%>
<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title></title>
    <script type="text/javascript" src="../scripts/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="../scripts/exodus/weapons.js"></script>
</head>
<body>
<c:catch var="exception">
<!-------------------------------------------
    - Begin weapons section -
    -------------------------------------------->
<table id="weaponsPanel">
    <tr>
        <th class="panelHeader">
            Weapons
        </th>
    </tr>
    <tr>
        <%--equipped weapons and ammo section--%>
        <c:choose>
            <%--the character has nothing equipped--%>
            <c:when test="${empty(sessionScope.equippedList)}">
                <td id="equipped" colspan="2">
                    <span class="italic">No weapon currently equipped.</span>
                </td>
            </c:when>
            <c:otherwise> <%--the character has a weapon equippped--%>
                <td class="equipped" colspan="2" id="${sessionScope.equippedList.get(0).serial}">
                        ${sessionScope.equippedList.get(0).name}
                </td>
            </c:otherwise>
        </c:choose>
        <td class="pipBoy" rowspan="4"></td>
    </tr>
    <tr>

        <c:forEach var="clip" items="${sessionScope.ammoList.get(sessionScope.equippedList.get(0).name)}">
            <c:if test="${clip.serial == sessionScope.equippedList.get(0).loaded}">
                <td id="loaded" colspan="2" data-serial="${clip.serial}">
                        ${clip.quantity} / ${clip.capacity}
                </td>
                <td>
                    <button class="refill" data-clip="loaded">Refill</button>
                </td>
                <td>
                    <button class="fire" data-clip="loaded">Fire</button>
                </td>
            </c:if>
        </c:forEach>
    </tr>
    <c:if test="${!empty(sessionScope.ammoList) || !empty(sessionScope.looseAmmoList)}">
        <tr>
            <th class="subHeader">Clips</th>
                <%--display all clips belonging to the equipped weapon--%>
        <th class="subHeader">Loose Ammunition(${sessionScope.equippedList.get(0).ammo})</th>
    </tr>
        <tr>
            <td>
                    <%--a nested table for all the clips of ammunition--%>
                <table id="clips" data-serial="${sessionScope.equippedList.get(0).serial}}">
                    <c:forEach var="clip"
                               items="${sessionScope.ammoList.get(sessionScope.equippedList.get(0).name)}"
                               varStatus="counter">
                        <c:if test="${clip.serial != sessionScope.equippedList.get(0).loaded}">
                            <tr>
                                <td class="clip" id="clip${counter.index}" data-serial="${clip.serial}">
                                        ${clip.quantity} / ${clip.capacity}
                                </td>
                                <td>
                                    <button class="reload" data-clip="clip${counter.index}">Reload</button>
                                </td>
                                <td>
                                    <button class="refill" data-clip="clip${counter.index}">Refill</button>
                                </td>
                            </tr>
                        </c:if>
                    </c:forEach>
                </table>
            </td>
            <td>
                <%--a list for all the loose ammunition--%>
                <ul>
                        <li id="loose" data-serial="${sessionScope.equippedList.get(0).ammo}">
                            ${sessionScope.looseAmmoList.get(sessionScope.equippedList.get(0).ammo)}
                        </li>
                </ul>
            </td>
        </tr>
    </c:if>
    <tr>
        <th class="weapons">Other Weapons</th>
    </tr>
    <tr>
        <td>
            <%--a subtable to hold the other weapons--%>
            <table class="weapons">
                <c:forEach var="weapon" items="${sessionScope.weaponList}" varStatus="counter">
                    <tr>
                        <td id="weapon${counter.index}" data-serial="${weapon.serial}" colspan="3">
                        ${weapon.name}<button class="equip" data-weapon="weapon${counter.index}">Equip</button>
                        </td>
                    </tr>
                </c:forEach>
            </table>
        </td>
    </tr>
</table>
<table id="aidPanel">
    <tr>
        <th class="panelHeader">Aid</th>
    </tr>
<tr>
    <td>
        <%--sub table containing food--%>
        <form class="food">
            <table class="food">
                <tr>
                    <th class="subHeader">Food</th>
                </tr>
                <c:forEach var="food" items="${sessionScope.foodList}">
                    <tr>
                        <td class="food" id="${food.itemid}">
                            ${food.name}<br />
                            <input type="checkbox" value="${food.name}" />
                            Consume <input type="text" class="eatlbs" /> lbs.
                            Total: ${food.weight} lbs.
                            Days to Spoil: ${food.daysToSpoil}
                            Rads: ${food.rads}
                        </td>
                    </tr>
                </c:forEach>
            </table>
        </form>
    </td>
    <td class="pipboy">
        <!--pip boy image here-->
    </td>
</tr>
    <tr>
        <td>
            <%--sub table containing food--%>
            <form class="water">
                <table class="water">
                    <tr>
                        <th class="subHeader">Water</th>
                    </tr>
                    <c:forEach var="water" items="${sessionScope.waterList}">
                        <tr>
                            <td class="food" id="${water.itemid}">
                                ${water.name}<br />
                                <input type="checkbox" value="${water.name}" />
                                Consume <input type="text" class="drinkqts" /> qts.
                                Total: ${water.quantity} qts.
                                Rads: ${water.rads}
                            </td>
                        </tr>
                    </c:forEach>
                </table>
            </form>
        </td>
    </tr>
</table>

<%--to do
<table id="questsPanel">
    <tr>
    <th class="panelHeader">Quests</th>
    </tr>
    <c:forEach var="quest" items="${sessionScope.}"
</table>--%>

<table id="buttons">
    <tr>
        <td class="navigation">Weapons</td>
        <td class="navigation">Aid</td>
        <td class="navigation">Quests</td>
    </tr>
</table>
</c:catch>
<c:if test="${!empty exception}">
    An exception occured:
    <br />
    ${exception.message}
</c:if>
</body>
</html>